image_count=`sudo docker images jenkins:ci_v01 -q|wc -l`
if [[ $image_count -eq 1 ]]; then
    echo "jenkins:ci_v01 exist."
elif [[ $image_count -eq 0 ]]; then
    echo "jenkins:ci_v01 does not exist, now building."
    sudo docker build -t jenkins:ci_v01 -f Dockerfile.jenkins .
    echo ""
    echo "building finished."
fi

sudo docker stop jenkins_tw
sleep 3
in_dir=`readlink -f .`
sudo docker run \
    --rm \
    -d \
    -u root \
    -v ${in_dir}/demo_code:/code \
    -v ${in_dir}/init_server_env:/opt/deploy_or_deliver \
    -v ${in_dir}/.ssh:/root/.ssh \
    --name jenkins_tw \
    -p 8080:8080 \
    -p 50000:50000 \
    jenkins:ci_v01
